﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Xml;
using System.Xml.Xsl;
using Ext.Net;

public partial class EstateDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string estateId = Request.QueryString["formID"];
        if (estateId != null)
        {
            if (!Page.IsPostBack)
            {
                SqlConnection myConnection2;
                SqlCommand myCommand2;
                SqlDataReader myDataReader2;

                string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["SiyahBayrakConnectionString"].ConnectionString;

                myConnection2 = new SqlConnection(strConn);
                myConnection2.Open();

                myCommand2 = new SqlCommand("selectEstate", myConnection2);
                myCommand2.CommandType = System.Data.CommandType.StoredProcedure;
                myCommand2.Parameters.AddWithValue("estateId", estateId);

                myDataReader2 = myCommand2.ExecuteReader();
                while (myDataReader2.Read())
                {
                    titlelb.Text = myDataReader2["title"].ToString();
                    IDlb.Text = myDataReader2["estateId"].ToString();
                }
            }
        }
    }

    [DirectMethod]
    public void sendMessage()
    {
        SqlConnection myConnection;
        SqlCommand myCommand;
        //SqlDataReader myDataReader;

        string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["SiyahBayrakConnectionString"].ConnectionString;

        myConnection = new SqlConnection(strConn);
        myConnection.Open();
        myCommand = new SqlCommand("sendMessage", myConnection);
        myCommand.CommandType = System.Data.CommandType.StoredProcedure;        

        string estateId = Request.QueryString["formID"];

        DateTime createDate;
        createDate = DateTime.Now;

        myCommand.Parameters.AddWithValue("estateId", estateId);
        myCommand.Parameters.AddWithValue("messageContent", TextField9.Text);
        myCommand.Parameters.AddWithValue("senderNameSurname", TextField1.Text);
        myCommand.Parameters.AddWithValue("senderEmail", TextField2.Text);
        myCommand.Parameters.AddWithValue("messageSubject", TextField3.Text);
        myCommand.Parameters.AddWithValue("senderPhone", TextField4.Text);
        myCommand.Parameters.AddWithValue("messageDate", createDate);
        
        myCommand.ExecuteNonQuery();
        msglbl.Text = "Your message has been saved.";
    }    
}